#include "VolumeRenderPCH.h"
#include "VolumeObj.h"

const std::string VolumeHeaderPath = "../VolumeData/Teddybear/Teddybear.header";
//const std::string VolumeHeaderPath = "F:/gitee/VolumeData/stag_beetle.header";

//**************************************************************************************************
//FUNCTION:
void CVolumeObj::initV()
{
	m_pVolumeTex = __createVolumeTex3D(VolumeHeaderPath);
	genTexture(m_pVolumeTex);

	ResourceManager::registerSharedData("VolumeName", m_pVolume->getVolumeName());
	ResourceManager::registerSharedData("VolumeWidth", m_pVolume->getWidth());
	ResourceManager::registerSharedData("VolumeHeight", m_pVolume->getHeight());
	ResourceManager::registerSharedData("VolumeDepth", m_pVolume->getDepth());

	ResourceManager::registerSharedData("TFTexExtent", static_cast<size_t>(m_pVolume->getMaxScalar()) + 1);
}

//**************************************************************************************************
//FUNCTION:
void CVolumeObj::updateV()
{
	//TODO: Update corresponding texture when volume changes.
}

//**************************************************************************************************
//FUNCTION:
std::shared_ptr<STexture> CVolumeObj::__createVolumeTex3D(const std::string& vFilePath)
{
	m_pVolume->loadHeader(vFilePath);

	auto pVolumeTex = std::make_shared<STexture>();
	pVolumeTex->InternalFormat = GL_RED;
	pVolumeTex->Width = m_pVolume->getWidth();
	pVolumeTex->Height = m_pVolume->getHeight();
	pVolumeTex->Depth = m_pVolume->getDepth();
	pVolumeTex->ExternalFormat = GL_RED;
	pVolumeTex->DataType = GL_UNSIGNED_BYTE;
	pVolumeTex->pDataSet.push_back(m_pVolume->getPtrOfScalarSet());

	pVolumeTex->Type4WrapR = GL_CLAMP_TO_EDGE;
	pVolumeTex->Type4WrapS = GL_CLAMP_TO_EDGE;
	pVolumeTex->Type4WrapT = GL_CLAMP_TO_EDGE;
	pVolumeTex->isMipmap = GL_FALSE;
	pVolumeTex->TextureType = STexture::ETextureType::Texture3D;

	return pVolumeTex;
}